package com.huike.stock_analysis.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;


import com.huike.stock_analysis.entity.RiskInfo;

/**
 * 
 * @author mzLEI
 * @date 2020年7月2日
 */

@Repository
public class RiskDao {
	
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 
	 * @param code
	 * @return
	 * 风险规避信息查询
	 */
	public List<RiskInfo> queryRisk(String code){
		String sql = "SELECT * FROM `ads_fxgb` WHERE `ads_id` = " + code + " ORDER BY `ads_date`";
		List<RiskInfo> riskInfos = jdbcTemplate.query(sql,  new RowMapper<RiskInfo>() {
			
			@Override
			public RiskInfo mapRow(ResultSet rs, int col) throws SQLException {
				RiskInfo riskInfo = new RiskInfo();
				riskInfo.setDate(rs.getDate("ads_date"));
				//riskInfo.setHistoryRatio(rs.getDouble("ads_lsbdl"));
				//riskInfo.setValume(rs.getDouble("ads_rjcjl"));
				riskInfo.setAccountRatio(rs.getDouble("ads_yszkzb"));
				riskInfo.setzTest(rs.getDouble("ads_zz"));
				riskInfo.setPb(rs.getDouble("ads_pb"));
				riskInfo.setPe(rs.getDouble("ads_pe"));
				return riskInfo;
			}
		});
		
		return riskInfos;
	}

}
